package cn.microven.mindmap.components.control;

import javafx.beans.property.SimpleIntegerProperty;
import javafx.scene.control.Label;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.TextAlignment;

public class MapNodeLabel extends Label {

    private boolean isBold = false;

    private String fontFamily = "KaiTi";

    private boolean isItalic = false;
  
    private SimpleIntegerProperty fontSize = new SimpleIntegerProperty(20);

    public MapNodeLabel() {
        this.setTextAlignment(TextAlignment.CENTER);
//        this.updateFont();
    }

    public int getFontSize() {
        return this.fontSize.getValue();
    }

    public SimpleIntegerProperty fontSizeProperty() {
        return fontSize;
    }

    public String getFontFamily() {
        return this.fontFamily;
    }

    public boolean isItalic() {
        return isItalic;
    }

    public boolean isBold() {
        return isBold;
    }

    public void updateFont() {
        Font font = Font.font(fontFamily,
                isBold?FontWeight.BOLD:FontWeight.NORMAL,
                isItalic?FontPosture.ITALIC:FontPosture.REGULAR,
                this.getFontSize()
                );
        this.setFont(font);
    }

    public void setBold(boolean bold) {
        isBold = bold;
        updateFont();
    }

    public void setFontFamily(String fontFamily) {
        this.fontFamily = fontFamily;
        updateFont();
    }

    public void setItalic(boolean italic) {
        isItalic = italic;
        updateFont();
    }

    public void setFontSize(int fontSize) {
        this.fontSize.setValue(fontSize);
        updateFont();
    }
}
